//	 ID : pallab81
// 	PROG : 11405
// 	LANG : C++
// 	2011-10-18-12.06.13 Tuesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}

int cases;
char G[10][10];
int maximum_move;
pair< int, int > me;
vector< pair<int,int> > pawns;
int total_pawn;
inline void Read(){
    scanf("%d",&maximum_move);
    fo(i,8){
        fo(j,8){
            cin>>G[i][j];
        }
    }
    pawns.clear();
    fo(i,8){
        fo(j,8){
            if( G[i][j]=='k' ){
                me =  mk(i,j) ;
                goto next;
            }
        }
    }
next :
    total_pawn=0;
    fo(i,8){
        fo(j,8){
            if( G[i][j]=='P' ){
                pawns.pb( mk(i,j) );
                ++total_pawn;
            }
        }
    }

}
int dist[10][10];
int r[]={-2,-2,+2,+2,-1,+1,-1,+1};
int c[]={-1,+1,-1,+1,-2,-2,+2,+2};
const int inf = (int)1e5;

inline int bfs(int sr, int sc, int dr, int dc){
    fo(i,8){
        fo(j,8){
            dist[i][j]=inf;
        }
    }
    queue< pair<int,int> > q;
    dist[sr][sc]=0;
    q.push( mk(sr,sc) );
    while( q.empty()==false ){
        sr = q.front().f;
        sc = q.front().s;
        q.pop();

        fo(i,8){
            int tr = sr+r[i];
            int tc = sc+c[i];
            if( tr<0 || tc<0 || tr>=8 || tc>=8 )continue;
            if( G[tr][tc]=='p' || G[tr][tc]=='K' )continue;
            int cur_dist = dist[sr][sc]+1;

            if( tr==dr && tc==dc ){
                return cur_dist;
            }
            if( G[tr][tc]=='P' )continue;
            if( cur_dist < dist[tr][tc] ){
                dist[tr][tc]=cur_dist;
                q.push( mk(tr,tc) );
            }

        }
    }
    return -1;
}

inline int go(int sr,int sc, int cd, int mask){
    if( __builtin_popcount(mask)==total_pawn ){
        return 1;
    }

    int nice = 0;
    for(int i=0;i<total_pawn;++i){
        if( ( mask&(1<<i) )==0 ){
            int dr = pawns[i].f;
            int dc = pawns[i].s;
            int d = bfs( sr,sc, dr,dc );
            if( d!=-1 && cd>=d ){
                G[dr][dc]='.';
                int v = go(dr,dc, cd-d, ( mask|(1<<i) )  );
                G[dr][dc]='P';
                if( v ==1 ){
                    nice=1;
                }
            }
        }
    }
return nice;
}
inline void Proc(){

   int v = go( me.f, me.s,  maximum_move, 0);
   if( v ){
       printf("Yes\n");
   }
   else{
       printf("No\n");
   }

}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("in","rt",stdin);
	#endif

    scanf("%d",&cases);
    while( cases-- ){
        Read();
        Proc();
    }

return 0;
}
